package com.xiaoma.thread.wait.wait;

/**
 * @author xiaomacdut
 * @date 2020年2月4日 下午5:05:42
 */
public class ThreadA extends Thread{
    
	private Object obj;

    public ThreadA(String name,Object obj){
    	super(name);
    	this.obj=obj;
    }
    
    @Override
    public void run(){
        System.out.println("TheadA start get lock..");
        synchronized(obj){
            try {
                System.out.println("TheadA start sleep");
                Thread.sleep(10000);// 使当前线程阻塞1秒
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            System.out.println(Thread.currentThread().getName() + " call notify()");
            //notify()或者notifyAll()调用时并不会真正释放对象锁, 必须等到synchronized方法或者语法块执行完才真正释放锁.
            obj.notify();
            System.out.println(Thread.currentThread().getName() + " after notify()");
        }
    }
}
